#include "optionServer.h"
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
void display_option(){
	fprintf(stderr,"Expected syntax: [-p | --port] <port> [-u | --users_file] files");
}

/* Analyse des options */
/* entête de la fonction à compléter */
int analyse(int argc, char *argv[],unsigned short int * port,char ** file){
        static struct option long_options[] = {
                   {"port", 1, 0, 'p'},
                   {"users_file", 1, 0, 'u'},
                   {0, 0, 0, 0}
        };
        int c;
        int option_index = 0;
	while (1){
		c=getopt_long(argc,argv,"p:u:",long_options,&option_index);
		if (c==-1){
			break;
		}
		switch (c){
			case 'p':
				*port=atoi(optarg);
#ifdef VERBOSE
				fprintf(stderr,"%s\n",optarg);
#endif
				break;
			case 'u':
				*file=calloc(strlen(optarg)+1,sizeof(char));
				memcpy(*file,optarg,strlen(optarg));
				break;
			case '?':
				return -1;
			default:
				break;
		}
	}
	return 0;
}
